﻿<%--<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRM.Models.TrainingsParticipants>>" %>--%>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<int>" %>
<%@ Import Namespace="CRM.Database.Model" %>
<%@ Import Namespace="CRM.Resourses" %>

<%
    var statusesCol = new TrainingParticipantsStatusesCollection();
    var participantsCol = new TrainingsParticipantsCollection();
    var schedulesCol = new TrainingsSchedulesCollection();
    var schedule = (TrainingsSchedules) schedulesCol.GetItemById(Model);
    var editMode = true;
    if (schedule != null)
        editMode = schedule.IsActual;
    
%>

<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdTrainingsParticipant";
                                        settings.KeyFieldName = "IdTrainingsParticipant";
                                        settings.CallbackRouteValues = new { Controller = "TC", Action = "TrainingsParticipantsListPartial", idTrainingsSchedule = Model };
                                        settings.SettingsPager.PageSize = 20;

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Name;
                                            column.FieldName = "ParticipantName";
                                            settings.Width = 100;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsPosition;
                                            column.FieldName = "ParticipantPosition";
                                            settings.Width = 100;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsCompany;
                                            column.FieldName = "CompanyName";
                                            settings.Width = 100;
                                            column.ReadOnly = true;
                                            //column.EditFormSettings.Visible = DefaultBoolean.False;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsContactName;
                                            column.FieldName = "ContactName";
                                            settings.Width = 100;
                                            column.ReadOnly = true;
                                            //column.EditFormSettings.Visible = DefaultBoolean.False;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsContactPhone;
                                            column.FieldName = "ContactPhone";
                                            settings.Width = 100;
                                            column.ReadOnly = true;
                                            //column.EditFormSettings.Visible = DefaultBoolean.False;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.TrainingsRequestNumber;
                                            column.FieldName = "IdTrainingsRequest";
                                            settings.Width = 100;
                                            column.ReadOnly = true;
                                        });

                                        //
                                        //Добавление комбобоксов
                                        //
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTrainingsParticipantsStatus";
                                            column.Caption = Resourses.TrainingParticipantsStatus;
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                comboBoxProperties.DataSource = statusesCol.TrainingParticipantsStatusesActiveList;
                                                comboBoxProperties.TextField = "LocalizedName";
                                                comboBoxProperties.ValueField = "IdTrainingParticipantsStatus";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса

                                        settings.CommandColumn.Visible = editMode;
                                        settings.CommandColumn.NewButton.Visible = false;
                                        settings.CommandColumn.DeleteButton.Visible = false;
                                        settings.CommandColumn.EditButton.Visible = editMode;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                        settings.Width = 600;
                                        //settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "TC", Action = "TrainingsParticipantsPartialAdd", key = Model.Key };
                                        //settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "TC", Action = "TrainingsParticipantsPartialDelete", key = Model.Key };
                                        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "TC", Action = "TrainingsParticipantsListPartialUpdate", idTrainingsSchedule = Model };
                                    }).Bind(participantsCol.GetParticipantsByScheduleId(Model)).GetHtml();
                                    //}).Bind(DB.GetTrainingsParticipantsByScheduleId(Model)).GetHtml();
%>